<?php

/**
 * @author Laurent SITTLER <lolo.sittler@gmail.com>
 * @author Alexandre GOMEZ <gomez.alexandre02@gmail.com>
 * @version 0.1
 */

/**
 * External Database Class
 */
class External_Database extends PDO {

    /**
     * Connect external database
     * @param DB $db
     */
    function __construct(DB $db) {
        try {
            if (strtoupper($db->GetType()->GetName()) == strtoupper('oracle'))
                parent::__construct('oci:dbname=' . $db->GetHost() . ':' . $db->GetPort() . '/' . $db->GetName() . '', $db->GetLogin(), $db->GetPassword());
            else if (strtoupper($db->GetType()->GetName()) == strtoupper('mysql'))
                parent::__construct('mysql:host=' . $db->GetHost() . ';port=' . $db->GetPort() . ';dbname=' . $db->GetName() . '', $db->GetLogin(), $db->GetPassword());
        } catch (PDOException $e) {
            Session::Set(Constants::$SESSION_error, $e->getMessage());
        }
    }

}
